package com.szeldon.declatest.declaration.scenario.parts;

import java.util.Properties;

import com.szeldon.declatest.eval.ConditionReturnValue;
import com.szeldon.declatest.eval.ScenarioPartEvaluator;
import com.szeldon.declatest.eval.exceptions.EvaluationException;
import com.szeldon.declatest.exec.AbstractTestsSuiteExecutor;
import com.szeldon.declatest.exec.TestSuiteExecHistory;
import com.szeldon.utils.ValuesUtils;

/**
 * Abstract superclass for all scenario parts that are conditions. Consists of:
 * <ul>
 * <li>left - left value</li>
 * <li>operator - operator used for comparison of left and right value</li>
 * <li>left - right value</li>
 * 
 * @author szeldon
 * 
 */
public abstract class ConditionPartDeclaration extends ScenarioPartDeclaration {

    protected String left;
    protected String operator;
    protected String right;
    protected String description;

    /**
     * Creates condition with given parameters.
     * 
     * @param left
     * @param operator
     * @param right
     * @param description
     */
    public ConditionPartDeclaration(String left, String operator, String right, String description) {
        this.left = ValuesUtils.checkNamedValueForNull("left", left);
        this.operator = ValuesUtils.checkNamedValueForNull("operator", operator);
        this.right = ValuesUtils.checkNamedValueForNull("right", right);
        this.description = ValuesUtils.checkNamedValueForNull("description", description);
    }

    public String getLeft() {
        return left;
    }

    public String getOperator() {
        return operator;
    }

    public String getRight() {
        return right;
    }

    public String getDescription() {
        return description;
    }

    @Override
    public boolean isCondition() {
        return true;
    }

    /**
     * Evaluates this condition using provided evaluator that is used for getting values, using plugins etc.
     * 
     * @param properties
     * 
     * @param singleThreadExecutor
     * 
     * @param evaluator
     * @param executor
     * @param history
     * @return
     * @throws EvaluationException
     *             Thrown when there was a problem during evaluation.
     */
    public ConditionReturnValue evaluate(Properties properties, AbstractTestsSuiteExecutor executor,
            ScenarioPartEvaluator evaluator, TestSuiteExecHistory history) throws EvaluationException {
        return evaluator.evaluateCondition(properties, executor, left, operator, right, history);
    }

}
